{{ page_settings_error_html|raw }}
{{ page_settings_html|raw }}

<iframe id="import_upload_iframe" name="import_upload_iframe" width="1" height="1" class="hide"></iframe>
<div id="import_form_status" class="hide"></div>
<div id="importmain" class="container-fluid">
    <img src="{{ image('ajax_clock_small.gif') }}" width="16" height="16" alt="ajax clock" class="hide">

    <script type="text/javascript">
        //<![CDATA[
        {% include 'import/javascript.twig' with {
            'upload_id': upload_id,
            'handler': handler,
        } only %}
        //]]>
    </script>

    <form id="import_file_form"
        action="{{ url('/import') }}"
        method="post"
        enctype="multipart/form-data"
        name="import"
        class="ajax"
        {%- if handler != 'PhpMyAdmin\\Plugins\\Import\\Upload\\UploadNoplugin' %}
            target="import_upload_iframe"
        {%- endif %}>

        {{ get_hidden_inputs(hidden_inputs) }}

        <div class="exportoptions" id="header">
            <h2>
                {{ get_image('b_import', 'Import'|trans) }}
                {% block title %}{% endblock %}
            </h2>
        </div>

        <div class="importoptions">
            <h3>{% trans 'File to import:' %}</h3>

            {# We don't have show anything about compression, when no supported #}
            {% if compressions is not empty %}
                <div class="formelementrow" id="compression_info">
                    <p>
                        {{ 'File may be compressed (%s) or uncompressed.'|trans|format(compressions|join(', ')) }}
                        <br>
                        {% trans 'A compressed file\'s name must end in <strong>.[format].[compression]</strong>. Example: <strong>.sql.zip</strong>' %}
                    </p>
                </div>
            {% endif %}

            <div class="formelementrow" id="upload_form">
                {% if is_upload and upload_dir is not empty %}
                    <ul>
                        <li>
                            <input type="radio" name="file_location" id="radio_import_file" required="required">
                            <label for="radio_import_file">{% trans 'Browse your computer:' %}</label>

                            <div id="upload_form_status" class="hide"></div>
                            <div id="upload_form_status_info" class="hide"></div>

                            <input type="file" name="import_file" id="input_import_file" aria-label="{% trans 'Browse your computer' %}">

                            {{ get_formatted_maximum_upload_size(max_upload_size) }}

                            <input type="hidden" name="MAX_FILE_SIZE" value="{{ max_upload_size }}">

                            <p>{% trans 'You may also drag and drop a file on any page.' %}</p>
                        </li>
                        <li>
                          <input type="radio" name="file_location" id="radio_local_import_file"
                            {{- timeout_passed_global is not empty and local_import_file is not empty ? ' checked' }}>
                          <label for="radio_local_import_file">
                            {{ 'Select from the web server upload directory [strong]%s[/strong]:'|trans|format(user_upload_dir)|sanitize }}
                          </label>

                          {% if local_files is same as(false) %}
                            {{ 'The directory you set for upload work cannot be reached.'|trans|error }}
                          {% elseif local_files is not empty %}
                            <select size="1" name="local_import_file" id="select_local_import_file" aria-label="{% trans 'Select file to import' %}">
                              <option value=""></option>
                              {{ local_files|raw }}
                            </select>
                          {% else %}
                            <em>{% trans 'There are no files to upload!' %}</em>
                          {% endif %}
                        </li>
                    </ul>
                {% elseif is_upload %}
                    <label for="input_import_file">{% trans 'Browse your computer:' %}</label>

                    <div id="upload_form_status" class="hide"></div>
                    <div id="upload_form_status_info" class="hide"></div>

                    <input type="file" name="import_file" id="input_import_file">

                    {{ get_formatted_maximum_upload_size(max_upload_size) }}

                    <input type="hidden" name="MAX_FILE_SIZE" value="{{ max_upload_size }}">

                    <p>{% trans 'You may also drag and drop a file on any page.' %}</p>
                {% elseif upload_dir is not empty %}
                  <label for="select_local_import_file">
                    {{ 'Select from the web server upload directory [strong]%s[/strong]:'|trans|format(user_upload_dir)|sanitize }}
                  </label>

                  {% if local_files is same as(false) %}
                    {{ 'The directory you set for upload work cannot be reached.'|trans|error }}
                  {% elseif local_files is not empty %}
                    <select size="1" name="local_import_file" id="select_local_import_file">
                      <option value=""></option>
                      {{ local_files|raw }}
                    </select>
                  {% else %}
                    <em>{% trans 'There are no files to upload!' %}</em>
                  {% endif %}
                {% else %}
                    {{ 'File uploads are not allowed on this server.'|trans|notice }}
                {% endif %}
            </div>

            <div class="formelementrow" id="charaset_of_file">
                {# Charset of file #}
                <label for="charset_of_file">{% trans 'Character set of the file:' %}</label>
                {% if is_encoding_supported %}
                    <select id="charset_of_file" name="charset_of_file" size="1">
                        {% for charset in encodings %}
                            <option value="{{ charset }}"
                                {% if (import_charset is empty and charset == 'utf-8')
                                    or charset == import_charset %}
                                    selected="selected"
                                {% endif %}>
                                {{ charset }}
                            </option>
                        {% endfor %}
                    </select>
                {% else %}
                  <select lang="en" dir="ltr" name="charset_of_file" id="charset_of_file">
                    <option value=""></option>
                    {% for charset in charsets %}
                      <option value="{{ charset.name }}" title="{{ charset.description }}"
                        {{- charset.name == 'utf8' ? ' selected' }}>
                        {{- charset.name -}}
                      </option>
                    {% endfor %}
                  </select>
                {% endif %}
            </div>
        </div>

        <div class="importoptions">
            <h3>{% trans 'Partial import:' %}</h3>

            {% if timeout_passed is defined and timeout_passed %}
                <div class="formelementrow">
                    <input type="hidden" name="skip" value="{{ offset }}">
                    {{ 'Previous import timed out, after resubmitting will continue from position %d.'|trans|format(offset) }}
                </div>
            {% endif %}

            <div class="formelementrow">
                <input type="checkbox" name="allow_interrupt" value="yes" id="checkbox_allow_interrupt"{{ is_allow_interrupt_checked|raw }}>
                <label for="checkbox_allow_interrupt">
                    {% trans 'Allow the interruption of an import in case the script detects it is close to the PHP timeout limit. <em>(This might be a good way to import large files, however it can break transactions.)</em>' %}
                </label>
            </div>

            {% if not (timeout_passed is defined and timeout_passed) %}
                <div class="formelementrow">
                    <label for="text_skip_queries">
                        {% trans 'Skip this number of queries (for SQL) starting from the first one:' %}
                    </label>
                    <input type="number" name="skip_queries" value="
                        {{- skip_queries_default|raw -}}
                        " id="text_skip_queries" min="0">
                </div>
            {% else %}
                {# If timeout has passed,
                   do not show the Skip dialog to avoid the risk of someone
                   entering a value here that would interfere with "skip" #}
                <input type="hidden" name="skip_queries" value="
                    {{- skip_queries_default|raw -}}
                    " id="text_skip_queries">
            {% endif %}
        </div>

        <div class="importoptions">
            <h3>{% trans 'Other options:' %}</h3>
            <div class="formelementrow">
                <input type="hidden" name="fk_checks" value="0">
                <input type="checkbox" name="fk_checks" id="fk_checks" value="1"{{ is_foreign_key_check ? ' checked' }}>
                <label for="fk_checks">{% trans 'Enable foreign key checks' %}</label>
            </div>
        </div>

        <div class="importoptions">
            <h3>{% trans 'Format:' %}</h3>
            <select id="plugins" name="format">
              {% for option in plugins_choice %}
                <option value="{{ option.name }}"{{ option.is_selected ? ' selected' }}>{{ option.text }}</option>
              {% endfor %}
            </select>

            {% for option in plugins_choice %}
              <input type="hidden" id="force_file_{{ option.name }}" value="true">
            {% endfor %}

            <div id="import_notification"></div>
        </div>

        <div class="importoptions" id="format_specific_opts">
            <h3>{% trans 'Format-specific options:' %}</h3>
            <p class="no_js_msg" id="scroll_to_options_msg">
                {% trans 'Scroll down to fill in the options for the selected format and ignore the options for other formats.' %}
            </p>
            {{ options|raw }}
        </div>
        <div class="clearfloat"></div>

        {# Japanese encoding setting #}
        {% if can_convert_kanji %}
            <div class="importoptions" id="kanji_encoding">
                <h3>{% trans 'Encoding Conversion:' %}</h3>
                {% include 'encoding/kanji_encoding_form.twig' %}
            </div>
        {% endif %}

        <div class="importoptions justify-content-end" id="submit">
            <input id="buttonGo" class="btn btn-primary" type="submit" value="{% trans 'Go' %}">
        </div>
    </form>
</div>
